package 华为OD机试B卷复用题.基础题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ53_找终点 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/基础题/input/53.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    static void Solution(Scanner in) {
        String[] sArray = in.nextLine().split(" ");
        int[] nums = new int[sArray.length];
        for (int i = 0; i < sArray.length; i++) {
            nums[i] = Integer.parseInt(sArray[i]);
        }
        int result = Integer.MAX_VALUE;
        // 根据第一步步长遍历
        for (int i = 1; i < nums.length / 2; i++) {
            int pos = i;
            int count = 1;
            while (pos < nums.length - 1) {
                pos += nums[pos];
                count++;
            }
            if (pos == nums.length - 1) {
                result = Math.min(result, count);
            }
        }
        if (result == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(result);
        }
    }
}
